﻿using System;
using System . Collections . Generic;
using System . IO;
using System . Linq;
using System . Runtime . InteropServices . WindowsRuntime;
using Windows . Foundation;
using Windows . Foundation . Collections;
using Windows . UI;
using Windows . UI . Xaml;
using Windows . UI . Xaml . Controls;
using Windows . UI . ViewManagement;
using Windows . UI . Xaml . Media . Animation;
using Windows . UI . Xaml . Controls . Primitives;
using Windows . UI . Xaml . Data;
using Windows . UI . Xaml . Input;
using Windows . UI . Xaml . Media;
using Windows . UI . Xaml . Navigation;
using GameClassLibrary;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace RichMan4LApp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class CreateGamePage : Page
    {

        public StartGameParameters Parameters { get; set; }

        public CreateGamePage ( )
        {
            this . InitializeComponent ( );
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo ( NavigationEventArgs e )
        {
            Parameters = e . Parameter as StartGameParameters;
        }

        private void Page_Loaded ( object sender , RoutedEventArgs e )
        {

            StartStoryBoard . Begin ( );
        }

        private void ConditionsToWinList_SelectionChanged ( object sender , object e )
        {
            if ( ConditionsToWinButton != null && ConditionsToWinList != null )
            {
                ConditionsToWinButton . Content = ConditionsToWinList?.SelectedItem;
                if ( ConditionsToWinList . SelectedItem as string != "资产最多" )
                {
                    Parameters . ConditionsToWin = ( long ) new NumberConvert ( ) . ConvertBack ( ConditionsToWinList . SelectedItem , null , null , null );
                }
                else
                {
                    Parameters . ConditionsToWin = long . MaxValue;
                }
            }
        }

        private void MoneyStartList_SelectionChanged ( object sender , object e )
        {
            if ( MoneyStartButton != null && MoneyStartList != null )
            {
                MoneyStartButton . Content = MoneyStartList?.SelectedItem;
                Parameters . StartMoney = ( long ) new NumberConvert ( ) . ConvertBack ( MoneyStartList . SelectedItem , null , null , null );
            }
        }

        private void GameTimeList_SelectionChanged ( object sender , object e )
        {
            if ( GameTimeButton != null && GameTimeList != null )
            {
                GameTimeButton . Content = GameTimeList?.SelectedItem;
                switch ( GameTimeList?.SelectedItem as string )
                {
                    case "无限":
                        {
                            Parameters . GameTime = TimeSpan . MaxValue;
                            break;
                        }
                    case "一年":
                        {
                            Parameters . GameTime = DateTime . Now . AddYears ( 1 ) - DateTime . Now;
                            break;
                        }
                    case "六个月":
                        {
                            Parameters . GameTime = DateTime . Now . AddMonths ( 6 ) - DateTime . Now;
                            break;
                        }
                    case "三个月":
                        {
                            Parameters . GameTime = DateTime . Now . AddMonths ( 3 ) - DateTime . Now;
                            break;
                        }
                    case "一个月":
                        {
                            Parameters . GameTime = DateTime . Now . AddMonths ( 1 ) - DateTime . Now;
                            break;
                        }
                }
            }
        }

        private void MainPageButton_Click ( object sender , RoutedEventArgs e )
        {
            EasyPage . Navigate ( typeof ( MainPage ) , null , "Cyan" , LeaveStoryBoard , BackGroundRect , Frame , RemoveControl , AddControl );
        }

        private void PlayerConfigPageButton_Click ( object sender , RoutedEventArgs e )
        {
            EasyPage . Navigate ( typeof ( PlayerConfigPage ) , Parameters , "Lime" , LeaveStoryBoard , BackGroundRect , Frame , RemoveControl , AddControl );
        }

        private void RemoveControl ( )
        {
            MainPageButton . Click -= MainPageButton_Click;
            PlayerConfigPageButton . Click -= PlayerConfigPageButton_Click;
        }

        private void AddControl ( )
        {
            MainPageButton . Click += MainPageButton_Click;
            PlayerConfigPageButton . Click += PlayerConfigPageButton_Click;
        }

    }
}

